/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mnstudent.dataacesslayer;

import mnstudent.global.SConnection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author lee
 */
public class DataConnection {
    //
//    private final String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
//                    "databaseName=DangKyMonHocHocPhi;integratedSecurity=true";
    //trungpv edit
    //private String connectionUrl = SConnection.strURL;

    protected Connection m_connect;

    public DataConnection() {
        //openConection();
    }

    public Connection getConnection() {
        return this.m_connect;
    }

    protected boolean openConection() {
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            //m_connect = DriverManager.getConnection(connectionUrl);
            //trungpv edit
            m_connect = DriverManager.getConnection(SConnection.strURL);
            System.out.println("Kết nối dữ liệu thành công");
            return true;
        } catch (ClassNotFoundException ex) {
            System.out.println("Không khởi động được driver");
            return false;
        } catch (SQLException ex) {
            ex.printStackTrace();
            System.out.println("Không mở được kết nối");
            return false;
        }
    }

    protected void closeConnection() {
        try {
            if (m_connect != null) {
                m_connect.close();
            }
        } catch (SQLException ex) {
            Logger.getLogger(DataConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
